# Make figures for paper
library(uds)
library(coda)
library(MASS)

data(democracy1946.2000)
load("post.uds.RData")
names <- c('Arat', 'BLM', 'Bollen', 'F. House', 'Hadenius',
           'PACL', 'Polity', 'Polyarchy', 'PRC', 'Vanhanen')
names12 <- c('Arat', 'BLM', 'Bollen', 'F. House', 'Hadenius',
           'PACL', 'Polity', 'Polyarchy', 'PRC', 'Vanhanen',
           'Munck', 'Mainwaring')

# Figure 2, PPD visualization
load("ppd.RData")
pdf("fit.pdf", width=9, height=6)
ppd.hist(post.uds, ppd)
# 12-rater version
#ppd.hist(post.uds, ppd, names=c("Arat", "BLM", "Bollen", "F. House",
#  "Hadenius", "PACL", "Polity", "Polyarchy", "PRC", "Vanhanen",
#  "Munck", "Mainwaring"))
dev.off()
rm(ppd)

# Figure 3 (UDS 2000) setup
i2000 <- democracy$year == 2000
names2000 <- democracy$country[i2000]
z2000 <- mcmc(post.uds$z)[,i2000]

# Figure 3, two columns (orig was 9 by 6.5)
pdf("uds2000.pdf", width=6, height=8)
latentpic(z2000, names2000, clen=96, line.xaxis = -.8,
  cex.xaxis=.75, cex.yaxis=.5, mar=c(.5, 6, 0, .25), lwd.pnt=.25,
  lwd.conf=1.5, padj.top=1.25, padj.bottom=-1.75, topaxis=F)
dev.off()

# Figure 3, split across two pages
latentpic(z2000, names2000, clen=96, line.xaxis = -.8,
  cex.xaxis=.75, cex.yaxis=.5, mar=c(.5, 6, 0, 0), lwd.pnt=.25,
  lwd.conf=1.5, padj.top=1.25, padj.bottom=-1.75, topaxis=F,
  fname="uds2000_", fwidth=6, fheight=8)

rm(i2000, names2000, z2000)

# Figure 5, cutoffs
pdf("cuts.pdf", width=9, height=6)
cutpic(post.uds, names=names)
dev.off()

# Figure 6, variances
pdf("vars.pdf", width=9, height=6)
varpic(post.uds, names=names)
dev.off()
